//
//  HTGoodsSearchCell.m
//  TruckUser
//
//  Created by Ting Han on 2017/10/16.
//  Copyright © 2017年 Ting Han. All rights reserved.
//

#import "HTGoodsSearchCell.h"
#import "UIImageView+WebCache.h"

@interface HTGoodsSearchCell()
@property (weak, nonatomic) IBOutlet UILabel *startLabel;
@property (weak, nonatomic) IBOutlet UILabel *endLabel;
@property (weak, nonatomic) IBOutlet UILabel *detialLabel;
@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *countLabel;
@property (weak, nonatomic) IBOutlet UIImageView *callImageView;
@property (weak, nonatomic) IBOutlet UILabel *ageLabel;

@end

@implementation HTGoodsSearchCell

- (void)setGoodsSearchModel:(HTGoodsSearchModel *)goodsSearchModel{
    _goodsSearchModel = goodsSearchModel;
    self.startLabel.text = goodsSearchModel.fromadd;
    self.endLabel.text = goodsSearchModel.toadd;
    
    NSString *length = [HTUtils sortLengthDisplayStringWith:goodsSearchModel.heiht];
    NSString *type = @"不限车型";
    if (!(goodsSearchModel.type == nil || goodsSearchModel.type.length <= 0)) {
        type = goodsSearchModel.type;
    }
    NSString *dun = @"";
    if ([goodsSearchModel.utit isEqualToString:@"1"]) {
        dun =[NSString stringWithFormat:@"%@吨",goodsSearchModel.weight];
    }else{
        dun =[NSString stringWithFormat:@"%@方",goodsSearchModel.weight];
    }
    NSString *cartype = @"";
    if (!(goodsSearchModel.cartype == nil || goodsSearchModel.cartype.length <= 0)) {
        cartype = goodsSearchModel.cartype;
    }
    self.detialLabel.text = [NSString stringWithFormat:@"%@ %@ / %@ %@ / 运费%@元",length,type,dun,cartype,goodsSearchModel.pricers];
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:goodsSearchModel.picurl] placeholderImage:[UIImage imageNamed:@"bg_headsculpture"]options:SDWebImageRefreshCached];
    self.nameLabel.text = goodsSearchModel.drivername;
    NSString *time =  [HTUtils timeIntervalFromLastTime:goodsSearchModel.createtime];
    if (![time isEqualToString:@"刚刚"]) {
        time = [NSString stringWithFormat:@"%@前",time];
    }
    self.timeLabel.text = time;
    self.countLabel.text = [NSString stringWithFormat:@"已发货%@条",goodsSearchModel.num];
    self.ageLabel.text = [NSString stringWithFormat:@"已注册%@",[HTUtils timeIntervalFromLastTime:goodsSearchModel.registime lastTimeFormat:@"YYYY-MM-dd"]];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    self.headImageView.userInteractionEnabled = YES;
    self.headImageView.layer.masksToBounds = YES;
    self.headImageView.layer.cornerRadius = kWidth(22.5);
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didTapCall)];
    self.callImageView.userInteractionEnabled = YES;
    [self.callImageView addGestureRecognizer:tap];
}
- (void)didTapCall{
    NSString *phone = self.goodsSearchModel.phone;
    NSString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",phone];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


@end
